package ParsingSAX;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.Arrays;

import javax.swing.tree.DefaultMutableTreeNode;



public class NodeTransferable implements Transferable {

	protected static final DataFlavor nodeFlavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType,"ContactNode");
	protected DefaultMutableTreeNode treeNode;
	
	public NodeTransferable(DefaultMutableTreeNode node) {
		super();
		System.out.println("init");
		treeNode = node ; 
	}
	
	public static DataFlavor getDataFlavor()
	{
		return nodeFlavor;
	}

	@Override
	public Object getTransferData(DataFlavor flavor)
			throws UnsupportedFlavorException, IOException {
		System.out.println("method getTransferData");
		if(flavor==nodeFlavor) return treeNode;
		else return null;

	}

	@Override
	public DataFlavor[] getTransferDataFlavors() {
		System.out.println("method getTransferDataFlavors");
		DataFlavor[] result = {nodeFlavor};
		return result;
	}

	@Override
	public boolean isDataFlavorSupported(DataFlavor flavor) {
		System.out.println("method isDataFlavorSupported");
		return Arrays.asList(getTransferDataFlavors()).contains(flavor);
	}

}
